from django.test import TestCase
from elasticsearch import Elasticsearch

# Create your tests here.
# 连接到Elasticsearch
es = Elasticsearch("http://114.55.177.21:9200")
# 初始化滚动上下文
query = {
    "query": {
        "match_all": {}
    },
    "size": 1000
}
# 执行搜索并获取初始的滚动ID
res = es.search(index="dingxiang_doctor", body=query, scroll='1m', params={"scroll": "1m"})
# print(res)
scroll_id = res.get("_scroll_id")
print(scroll_id,"scroll_id")
hits = res.get("hits", {}).get("hits", [])
# # 循环获取后续数据
# 循环获取后续数据
while True:
    # 滚动获取数据
    res = es.scroll(scroll_id=scroll_id, scroll='1m')
    print(res)
    # 如果没有更多的数据，则退出循环
    if not res.get("hits", {}).get("hits"):
        break
    hits = res.get("hits", {}).get("hits", [])
    for hit in hits:
        print(hit)
    print(f"Scroll ID: {res.get('_scroll_id')}")
print({"ok": hits})
